﻿using System;
using System.Collections.Generic;
using System.IdentityModel.Selectors;
using System.IdentityModel.Tokens;
using System.Web.Security;

namespace WcfService
{
    public class CustomUserNameValidator : UserNamePasswordValidator
    {
        public override void Validate(string username, string password)
        {

            if (null == username || null == password)
            {
                throw new ArgumentNullException();
            }


            if (!dUser.ContainsKey(username) || dUser[username] != password)
            {
                Membership.GetUser(username);
                string mk = FormsAuthentication.HashPasswordForStoringInConfigFile(Membership.GetUser(username).GetPassword(), "SHA1");
                if (mk != password)
                {
                    throw new SecurityTokenException("Unknown Username or Password");
                }
                //if (!Membership.ValidateUser(username, password))
                //    throw new SecurityTokenException("Unknown Username or Password");
                else
                {
                    if (dUser.ContainsKey(username))
                        dUser[username] = password;
                    else
                        dUser.Add(username, password);
                }
            }

        }
        internal static Dictionary<string, string> dUser = new Dictionary<string, string>();
    }
}
